package main

import (
	"encoding/json"
	"fmt"
	"gitee.com/DengAnbang/Wefore/src/api"
	"gitee.com/DengAnbang/Wefore/src/bean"
	"gitee.com/DengAnbang/Wefore/src/config"
	"gitee.com/DengAnbang/Wefore/src/dbops"
	_ "gitee.com/DengAnbang/Wefore/src/dbops"
	"gitee.com/DengAnbang/Wefore/src/socket"
	"gitee.com/DengAnbang/goutils/loge"
	"gitee.com/DengAnbang/goutils/sysUtils"
	"net/http"
)

func main() {
	//ShowBeanJson()
	err := sysUtils.Install("服务", "服务", "此服务程序为后端服务功能",
		func() {
			loge.W("准备开启服务..", config.ConfigBean.ApiPort)
			//go socket.TcpRun(config.ConfigBean.SocketPort)
			mux := http.NewServeMux()
			mux.HandleFunc("/pc/websocket", socket.WebSocketRun)
			api.Run(config.ConfigBean.ApiPort, mux)
		})
	if err != nil {
		loge.W(err)
		panic(err)
	}

}
func ShowBeanJson() {
	a := make([]dbops.StructureTreeBean, 1)
	getJson := GetJson(dbops.UserBean{Structures: &a})
	fmt.Println("UserBean:" + getJson)
	fmt.Println("TreeBean:" + GetJson(bean.TreeBean{}))
	fmt.Println("FileTreeBean:" + GetJson(dbops.FileTreeBean{}))
	fmt.Println("ProjectTreeBean:" + GetJson(dbops.ProjectTreeBean{}))
	fmt.Println("StructureTreeBean:" + GetJson(dbops.StructureTreeBean{}))
	fmt.Println("FileBean:" + GetJson(dbops.FileBean{}))
}
func GetJson(i interface{}) string {
	bytes, err := json.Marshal(i)
	if err != nil {
		return ""
	}
	return string(bytes)
}
